package com.yswl.yeeduo.ui.base;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yswl.yeeduo.R;
import com.yswl.yeeduo.base.KActivity;

/**
 * 
 * 定义标题栏 和 进度条
 * 
 * @author kangpeng
 */
public abstract class BaseActivity extends KActivity {

	/** 标题bar **/
	public LinearLayout navigation;
	/** 回退按钮 **/
	public ImageView mBack;
	/** 中间标题 **/
	public TextView mTitle;
	/** 右边 **/
	public ImageView mRight;

	// public ImageView progressBar;

	/** 设置标题栏（可定制标题栏事件处理类） */
	protected void setHeader(View.OnClickListener backEvt, String titleName) {
		mBack = (ImageView) findViewById(R.id.nav_left);
		mTitle = (TextView) findViewById(R.id.nav_title);
		mRight = (ImageView) findViewById(R.id.nav_right);
		navigation = (LinearLayout) findViewById(R.id.navigation);// webView
																	// 需要隐藏

		if (mBack != null) {
			mBack.setVisibility(View.VISIBLE);
		}
		if (mRight != null) {
			mRight.setVisibility(View.INVISIBLE);
		}
		// 如果不定制事件处理类，默认退回主页
		if (backEvt == null) {
			backEvt = new OnClickListener() {
				@Override
				public void onClick(View arg0) {
					// Intent intent = new Intent(BaseActivity.this,
					// MainActivity.class);
					// startActivity(intent);
					// overridePendingTransition(
					// R.anim.back_left_in,R.anim.back_right_out);
					finish();
				}
			};
		}
		mBack.setOnClickListener(backEvt);
		// 设置标题名称
		mTitle.setText(titleName);

	}

	/** 设置标题栏 */
	protected void setHeader(String titleName) {
		setHeader(null, titleName);
	}

	/*
	 * protected void startProgress() { progressBar = (ImageView)
	 * findViewById(R.id.head_progressBar); if (progressBar != null) {
	 * progressBar.setVisibility(View.VISIBLE); //
	 * progressBar.setBackgroundResource(R.anim.progress_img); AnimationDrawable
	 * anim = (AnimationDrawable) progressBar.getBackground(); anim.start(); }
	 * 
	 * }
	 * 
	 * protected void closeProgress() { if (progressBar != null) {
	 * progressBar.setVisibility(View.GONE); } }
	 */

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);

	}

}
